<?php

class OrdersnController extends UserLoginBaseC{
	/**
	 * 充值
	 * @return [type] [description]
	 */
	public function actionIndex(){
		if(IS_POST){
			if(empty($_POST['money']) || !is_numeric($_POST['money'])){
				$this->error('请填写正确的金额');
			}
			Yii::import('ext.alipay.*');
			$alipay = new Alipay();
            $orders = array(
                'Type' => 1,
                'Money' => $_POST['money'],
            );
            if ($alipay->data($orders)->createOrders() !== true) {
                $error = $alipay->getError();
                $this->error($error ? $error : '订单创建失败，请重新提交！');
            }
            //跳转到支付宝支付页面
            $url = $alipay->payment(true);
            if ($url == false) {
                $error = $alipay->getError();
                $this->error($error ? $error : '订单处理错误！');
            } else {
                $this->success('报名成功，马上前往支付页面！', $url);
                exit;
            }            			
		}
	}
}